<?php
require_once 'config21.php';
if (!isset($_SESSION['userid'])) {
    header("Location: login21.php");
    exit;
}

// 查询所有鸟类介绍信息
$sql = "SELECT * FROM introduce";
$result = $conn->query($sql);
?>

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>鸟类介绍列表</title>
    <link rel="stylesheet" href="style21.css">
</head>

<body>
    <header>
        <h1>鸟类介绍列表</h1>
    </header>
    <nav>
        <a href="index.php">首页</a>
        <a href="list_nationalbird21.php">国家鸟类列表</a>
        <a href="list_introduce21.php">鸟类介绍列表</a>
        <a href="logout21.php">退出登录</a>
    </nav>
    <div class="container">
        <a href="add_introduce21.php">添加鸟类介绍信息</a>
        <table>
            <tr>
                <th>编号</th>
                <th>名称</th>
                <th>别名</th>
                <th>介绍</th>
                <th>日期时间</th>
                <th>操作</th>
            </tr>
            <?php
            if ($result->num_rows > 0) {
                while ($row = $result->fetch_assoc()) {
                    echo "<tr>";
                    echo "<td>". $row['no']. "</td>";
                    echo "<td>". $row['name']. "</td>";
                    echo "<td>". $row['anothername']. "</td>";
                    echo "<td>". substr($row['intro'], 0, 50). "...</td>";
                    echo "<td>". $row['datetime']. "</td>";
                    echo "<td>";
                    echo "<a href='edit_introduce21.php?id=". $row['no']. "'>编辑</a> | ";
                    echo "<a href='delete_introduce21.php?id=". $row['no']. "'>删除</a>";
                    echo "</td>";
                    echo "</tr>";
                }
            } else {
                echo "<tr><td colspan='6'>暂无数据</td></tr>";
            }
            ?>
        </table>
    </div>
</body>

</html>